//
//  HQYSearchControlView.m
//  HONGQIYUN
//
//  Created by leihuiwu on 16/12/21.
//  Copyright © 2016年 Haidi. All rights reserved.
//

#import "HQYSearchControlView.h"


const static CGFloat kTextFieldLeftInterval = 1;
const static CGFloat kTextFieldTopInterval = 1;
const static CGFloat kTextFieldBottomInterval = 1;
const static CGFloat kSeactBtnWidth = 50.f;

@interface HQYSearchControlView ()

@property (nonatomic,   copy) NSString    *placeholderText;

@property (nonatomic, strong) UITextField *searchTF;

@property (nonatomic, strong) UIButton *voiceBtn;

@property (nonatomic, strong) UIButton *searchBtn;

@end

@implementation HQYSearchControlView

- (id)initWithFrame:(CGRect)frame andPlaceholderText:(NSString *)placeholderText {
    if(self = [super initWithFrame:frame]) {
        self.placeholderText = placeholderText;
        
        [self viewLayout];
    }
    return self;
}

- (void)viewLayout {
    self.layer.cornerRadius = 4.f;
    self.layer.borderColor = [UIColor colorFromHexString:@"#DD1422"].CGColor;
    self.layer.borderWidth = 1.f;

    self.backgroundColor = [UIColor colorFromHexString:@"#DD1422"];
    
    [self addSubview:self.searchTF];
    [self.searchTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kTextFieldLeftInterval);
        make.top.equalTo(self.mas_top).offset(kTextFieldTopInterval);
        make.bottom.equalTo(self.mas_bottom).offset(-kTextFieldBottomInterval);
        make.right.equalTo(self.mas_right).offset(-kSeactBtnWidth);
    }];
    
    [self addSubview:self.voiceBtn];
    [self.voiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-kSeactBtnWidth);
        make.width.equalTo(@(40));
        make.height.equalTo(self.mas_height);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    [self addSubview:self.searchBtn];
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.top.equalTo(self.mas_top).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.width.equalTo(@(kSeactBtnWidth));
    }];
    
    self.searchTF.placeholder = self.placeholderText;
}

#pragma mark - action
- (void)voiceBtnAction {
    
}

- (void)searchBtnAction {
    
}

#pragma mark - lazy load
- (UITextField *)searchTF {
    if(!_searchTF) {
        _searchTF = [[UITextField alloc]init];
        _searchTF.backgroundColor = [UIColor whiteColor];
        _searchTF.font = [UIFont systemFontOfSize:14];
    }
    return _searchTF;
}

- (UIButton *)voiceBtn {
    if(!_voiceBtn) {
        _voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_voiceBtn setImage:[UIImage imageNamed:@"lawLibrary_voiceIcon"] forState:UIControlStateNormal];
        [_voiceBtn addTarget:self action:@selector(voiceBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _voiceBtn;
}

- (UIButton *)searchBtn {
    if(!_searchBtn) {
        _searchBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [_searchBtn setTitle:@"查找" forState:UIControlStateNormal];
        [_searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _searchBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _searchBtn;
}


@end
